<template>

  <div>
    <!-- 按钮 -->
    <div class="btns">
      <el-form label-width="40px" inline style="text-align: center
      ">
        <el-form-item label="名称">
          <el-input v-model="param.name"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="loadCategorys">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-form style="text-align:right">
        <el-form-item>
      <el-button type="primary" size="small" @click="toAddHandler" style="text-align:right">新增</el-button>
        </el-form-item>
      </el-form>
    </div>  
     <!-- /按钮 -->
    <!-- {{baseuserroles}} -->
    <!-- 表格 -->
  
    <el-table size="small" :data="categorys">
      <el-table-column type="index" :index="1" label="序号"></el-table-column>
      <el-table-column label="名称" prop="name" align="center"></el-table-column>
      <el-table-column label="描述" prop="description" align="center"></el-table-column>
      <el-table-column label="no"  prop="no" align="center"></el-table-column>
      <el-table-column label="parentId" prop="parentId"   align="center"></el-table-column>
      <el-table-column label="操作" width="150" align="center">
      <template slot-scope="scope">
        <el-button type="text" icon="el-icon-edit" size="mini" @click="editHandler(scope.row)"></el-button> 
        <el-button type="text" icon="el-icon-delete" size="mini" @click="deleteHandler(scope.row)"></el-button>
      </template>

      </el-table-column>
    </el-table>
    <!-- /表格 -->
  </div>
</template>

<script>
import { del, get,} from "@/utils/request";
export default {
  //页面数据
  data() {
    return {
      categorys: [],
      param: {},
    };
  },
  //页面渲染的时候会调用的函数
 
  
  methods: {
    //修改
    editHandler(row){
      //跳转到修改页面（新增）
      //携带当前行所带数据
      this.$router.push({
        path:"/category/create",  //跳转的路由
        query:row  //携带参数
      })
    },
    //删除
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://localhost:8888/category/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadCategorys();
        });
      });
    },
    //跳转
    toAddHandler() {
      this.$router.push("/category/create");
    },
    //
    loadCategorys() {
      let url = "http://localhost:8888/category/query";
      get(url, this.param).then((resp) => {
        this.categorys = resp.data;
      });
    },
  },
    
    created() {
      this.loadCategorys();
    
  },
};
</script>
<style scoped>
.btns {
  margin-bottom: 0.5em;
}
</style>